package com.yanqu.road.server.cmd.activity.hsisland;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.HsIslandProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.hsisland.CrossHsIslandActivity;
import com.yanqu.road.server.manager.activity.hsisland.CrossHsIslandActivityMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C2_HS_ISLAND_DEBUG_CODE, desc = "海神岛GM指令")
public class CrossHsIslandDebugCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        HsIslandProto.HsIslandDebugReqMsg reqMsg = HsIslandProto.HsIslandDebugReqMsg.parseFrom(packet.getBytes());
        CrossHsIslandActivity activity = CrossHsIslandActivityMgr.getActivity(reqMsg.getActivityId(), groupId);
        if (activity == null) {
            return;
        }
        try {
            activity.debugCode(reqMsg, packet.getPlayerId());
        } catch (BusinessException e) {
            HsIslandProto.HsIslandEnterActivityRespMsg.Builder respMsg = HsIslandProto.HsIslandEnterActivityRespMsg.newBuilder();
            respMsg.setRet(e.getCode());
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_HS_ISLAND_ENTER_ACTIVITY, respMsg));
        }
    }

    @Override
    public void sendData() {}
}
